var DayAccountList = Class.create(AbstractList,{
  initialize:function($super,args)
  {
    args.url='/account.json',
    $super(args);
  },
  createDataSet:function(dataSet)
  {
      this.sum=0;
      var tableData = {option:'style="width:48em;" class="account_list"',
          header:[{name:'項目',sort:'normal',width:'8em'},{name:'金額',sort:'number',width:'8em'},{name:'内容',sort:'normal',width:'16em'},{name:'操作',width:'6em'}],data:[]};

      for(var i=0;i<dataSet.length;i++)
      {
        var rec = new Array();
        var data = dataSet[i];
        rec.push(data.category);
        this.sum += data.price;
        rec.push(myFormatNumber(data.price)+'円');
        rec.push(data.content);
        rec.push('<a href="editAccount?key='+data.key+'" >編集</a>' +
            '<input type="button" class="day_account_list_delete" value="削除" id="'+data.key+'" />');
        tableData.data.push(rec);
      }
      this.callBack(tableData);
  },
  addObserve:function()
  {
    $$(".day_account_list_delete").each(function(elem){
      if(elem.value=="削除")
      {
        elem.observe('click', function(event){this.deleteAccount(event.element().id);}.bind(this));
      }
    }.bind(this));
  },
  deleteAccount:function(key)
  {
    var cfm = window.confirm("本当に削除していいですか?");
    if(cfm!=true)
      return false;
    var a = new Ajax.Request( 
        "/deleteAccount", 
        { 
            "method": "post", 
            "parameters": "key="+key, 
            onSuccess: function(request) { 
              this.loadData();
            }.bind(this), 
            onFailure: function(request) { 
                alert('読み込みに失敗しました'); 
            }, 
            onException: function (request) { 
                alert('読み込み中にエラーが発生しました'); 
            } 
        }); 
    return false;
  }
});
